exports.filterTag=function(str){
	return str.replace(/<.+?>/gi,'');
}
exports.clearTag=function(){
	let input=document.querySelectorAll('input,textarea');
	[...input].forEach(inpt=>{
		inpt.onkeyup=function(){
			var v=this.value,r=/[<>/\\"?*:]/g;
			if (r.test(v)) {
				this.value=v.replace(r,'');
			}
		}
	});
}
function isIE(){
	return /msie\s\d/i.test(navigator.userAgent);
}
function getAgrsType(agrs){
	return Object.prototype.toString.call(agrs).toLowerCase().split(/\s+/)[1].slice(0,-1);
}
exports.isIE=isIE();
exports.winSize=function(){
	return {
		width:isIE()?document.documentElement.scrollWidth:window.innerWidth,
		height:isIE()?document.documentElement.scrollHeight:window.innerHeight
	}
}
exports.addUrlParams=function(url,pars){
	if (!pars||!Object.keys(pars).length) return url;
	var urlMatched=url.match(/(.+?)(#.*?)?$/);
	var newUrl=url;
	if (urlMatched) {
		var _url=urlMatched[1];
		var _pars=[];
		for(var p in pars){
			_pars.push(p+'='+pars[p]);
		}
		if (_url) {
			_url+=((/\?.*$/i.test(_url)?'&':'?')+_pars.join('&'));
		}
		newUrl=_url+(urlMatched[2]||'');
	}
	return newUrl;
}
exports.DOMEvent={
	add:function(obj,type,fn){
		fn['evt_id']=function(_e){
			var e=_e||window.event;
			var evt={
				target:e.target||e.srcElement,
				stopPropagation:function(){
					e.stopPropagation?e.stopPropagation():e.cancelBubble=true;
				},
				preventDefault:function(){
					e.preventDefault?e.preventDefault():e.returnValue=false;
				},
				clientX:e.clientX,
				clientY:e.clientY
			}
			fn.call(obj,evt);
		}
		obj.addEventListener?obj.addEventListener(type,fn['evt_id'],false):obj.attachEvent('on'+type,fn['evt_id']);
	},
	free:function(obj,type,fn){
		obj.addEventListener?obj.removeEventListener(type,fn['evt_id']):obj.detachEvent('on'+type,fn['evt_id']);
	}
}
function rand(){
	return Math.random().toString(18).slice(2,12);
}
exports.rand=rand;
exports.nickTime=function(timeStamp){
	var d=Date.now(),
		fill0=function(x){return x<10?'0'+x:x;};
	if (!/^\d+$/g.test(timeStamp)) timeStamp=d;
	var len=d-timeStamp,
		fmtTime=function(s){
			var d=new Date(s);
			return d.getFullYear()+
					'-'+fill0(d.getMonth()+1)+
					'-'+fill0(d.getDate())+
					' '+fill0(d.getHours())+
					':'+fill0(d.getMinutes());
		};
	return len<=60*1000?'刚刚':
		   len<60*60*1000?`${~~(len/60/1000)}分钟前`:
		   len<24*60*60*1000?`${~~(len/60/60/1000)}小时前`:
		   fmtTime(timeStamp);
}
exports.getAgrsType=getAgrsType;
exports.cssTextify=function(cs){
	function cssifyObj(obj){
		var arr=[];
		for(var css in obj){
			var attr=css;
			if (/[A-Z]/.test(css)) {
				attr=css.replace(/[A-Z]/g,function(a){
					return '-'+a.toLowerCase();
				});
			}
			arr.push(attr+':'+obj[css]);
		}
		return arr.join(';');
	}
	return typeof cs==='string'?
		cs:
		getAgrsType(cs)==='object'?
		cssifyObj(cs):
		''
}
exports.$$=function(el, all) {
	return document[all? 'querySelectorAll': 'querySelector'].call(document, el);
}
exports.getClass=function(box,clas,fn){
	var ods=box.getElementsByTagName('div');
	for(var i=0;i<ods.length;i++){
		if (~ods[i].className.indexOf(clas)) {
			fn&&fn(ods[i]);
			break;
		}
	}
}
exports.debounce = function(func, wait, immediate) {
    var timeout, args, context, timestamp, result;

    var later = function() {
      var last = new Date().getTime() - timestamp;

      if (last < wait && last >= 0) {
        timeout = setTimeout(later, wait - last);
      } else {
        timeout = null;
        if (!immediate) {
          result = func.apply(context, args);
          if (!timeout) context = args = null;
        }
      }
    };

    return function() {
      context = this;
      args = arguments;
      timestamp = new Date().getTime();
      var callNow = immediate && !timeout;
      if (!timeout) timeout = setTimeout(later, wait);
      if (callNow) {
        result = func.apply(context, args);
        context = args = null;
      }

      return result;
    };
};
exports.throttle = function(func, wait, options) {
    var context, args, result;
    var timeout = null;
    var previous = 0;
    if (!options) options = {};
    var later = function() {
      previous = options.leading === false ? 0 : new Date().getTime();
      timeout = null;
      result = func.apply(context, args);
      if (!timeout) context = args = null;
    };
    return function() {
      var now = new Date().getTime();
      if (!previous && options.leading === false) previous = now;
      var remaining = wait - (now - previous);
      context = this;
      args = arguments;
      if (remaining <= 0 || remaining > wait) {
        if (timeout) {
          clearTimeout(timeout);
          timeout = null;
        }
        previous = now;
        result = func.apply(context, args);
        if (!timeout) context = args = null;
      } else if (!timeout && options.trailing !== false) {
        timeout = setTimeout(later, remaining);
      }
      return result;
    };
};